package com.example.demo01minio.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * ClassName:TestMateObjectHandler
 * Package:com.example.demo01minio.handler
 * Description:
 *
 * @Author:helei
 * @Create:2024/8/27 - 16:00
 */
@Component
public class TestMateObjectHandler implements MetaObjectHandler {

    //新增时触发的回调
    @Override
    public void insertFill(MetaObject metaObject) {
        if (metaObject.hasSetter("createTime")) {
            metaObject.setValue("createTime", new Date());
        }
        if (metaObject.hasSetter("updateTime")) {
            metaObject.setValue("updateTime", new Date());
        }
    }

    //更新时触发的回调
    @Override
    public void updateFill(MetaObject metaObject) {
        if (metaObject.hasSetter("updateTime")) {
            metaObject.setValue("updateTime", new Date());
        }
    }
}
